package com.huawei.appgallery.forum.option.comment.view;

import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;
import o.bqy;
import o.btg;
import o.btu;
import o.btw;
import o.byc.b;
import o.byc.c;
import o.byc.f;
import o.byc.j;
import o.bym;
import o.bys;

public class UpdateCommentContentLayout extends LinearLayout implements bys, btg {
    private RelativeLayout ˊ;
    private TextView ˋ;
    private EditTextWithListView ˎ;
    private int ˏ;
    private e ॱ;

    interface e {
        void ᐝ();
    }

    class d implements TextWatcher {
        final /* synthetic */ UpdateCommentContentLayout ˊ;
        private boolean ˎ;

        private d(UpdateCommentContentLayout updateCommentContentLayout) {
            this.ˊ = updateCommentContentLayout;
            this.ˎ = false;
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            this.ˎ = btw.ॱ(this.ˊ.ˎ, i);
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (this.ˎ) {
                btw.ˊ(i, this, this.ˊ.ˎ);
            }
        }

        public void afterTextChanged(Editable editable) {
            if (this.ˊ.ॱ != null) {
                this.ˊ.ॱ.ᐝ();
            }
            this.ˊ.ˋ.setText(this.ˊ.getResources().getString(j.ͺ, new Object[]{Integer.valueOf(editable.length()), Integer.valueOf(this.ˊ.ˏ)}));
            if (editable.length() < this.ˊ.ˏ) {
                this.ˊ.ˋ.setTextColor(this.ˊ.getResources().getColor(o.byc.e.ˊ));
                this.ˊ.ˊ.setBackgroundResource(c.ʽ);
            }
        }
    }

    public void ˊ() {
        this.ˋ.setTextColor(getResources().getColor(o.byc.e.ʼ));
        this.ˊ.setBackgroundResource(c.ᐝ);
        Animation loadAnimation = AnimationUtils.loadAnimation(getContext(), b.ॱ);
        if (loadAnimation != null) {
            this.ˊ.startAnimation(loadAnimation);
        }
    }

    public void ˊ(View view, int i, int i2) {
        if (view instanceof EditText) {
            btw.ˋ(i, i2, (EditText) view);
        }
    }

    public void ॱ(int i) {
    }

    public UpdateCommentContentLayout(Context context) {
        this(context, null);
    }

    public UpdateCommentContentLayout(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public UpdateCommentContentLayout(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˏ = IPRoute.INTERVAL;
        ˊ(context);
    }

    public void setContentChangeListener(e eVar) {
        this.ॱ = eVar;
    }

    private void ˊ(Context context) {
        View inflate = LayoutInflater.from(context).inflate(f.ʻ, this);
        this.ˎ = (EditTextWithListView) inflate.findViewById(o.byc.d.ˊᐝ);
        this.ˋ = (TextView) inflate.findViewById(o.byc.d.ˊˊ);
        this.ˋ.setText(getResources().getString(j.ͺ, new Object[]{Integer.valueOf(0), Integer.valueOf(this.ˏ)}));
        this.ˊ = (RelativeLayout) inflate.findViewById(o.byc.d.ˊˋ);
        ˋ();
    }

    private void ˋ() {
        this.ˎ.setSelectionChangedListener(this);
        this.ˎ.addTextChangedListener(new d());
        this.ˎ.setFilters(new InputFilter[]{new bym(this.ˏ, this)});
    }

    public EditText ॱ() {
        return this.ˎ;
    }

    public void setMaxCount(int i) {
        this.ˏ = i;
        this.ˋ.setText(getResources().getString(j.ͺ, new Object[]{Integer.valueOf(0), Integer.valueOf(i)}));
        ˋ();
    }

    public void setText(String str) {
        this.ˎ.setText(btu.ॱ(bqy.ˋ().ˏ(), str, btu.ˏ()));
    }

    public void setHint(String str) {
        this.ˎ.setHint(str);
    }
}
